import uuid
import time
from typing import List,Dict

#定义一个slot结构
class Slot:
    def __init__(self,slot_id:str,content:str,role:str,metadata:Dict):
        self.slot_id=slot_id
        self.content=content
        self.role=role
        self.metadata=metadata or {}

    def to_dict(self) :
        return{
            'slot_id':self.slot_id,
            'content':self.content,
            'role':self.role,
            'metadata':self.metadata
        }


#构造用户投诉的上下文slot列别
def build_complaint_slots()->List[Slot]:
    slots = []
    #首次输入
    slots.append(
        Slot(
            slot_id=uuid.uuid4().hex,
            content="我购买的洗衣机启动后电机异常响声，请尽快处理",
            role='user',
            metadata={
                'user_id':"1234",
                'timestamp':int(time.time()),
                'channel':"web_form"
            }
        )
    )

    #系统自动识别意图
    slots.append(
        Slot(
            slot_id=uuid.uuid4().hex,
            content='识别意图：产品故障-点击异常',
            role='system',
            metadata={
                "source":"intent_classifier_v2",
                "confidence":0.8
            }
        )
    )

    # agnet发出初步回复
    slots.append(Slot(
        slot_id=uuid.uuid4().hex,
        content='已记录问题，请提供产品序列号与购机发票照片已便安排售后服务',
        role='agent',
        metadata={
            'agent_id':uuid.uuid4().hex,
            'status':"response_issue"
        }
    ))

    return slots

if __name__ == '__main__':
    slots= build_complaint_slots()
    print('构建上下文slot结构====')
    for idx,slot in enumerate(slots):
        print(f"\n[slot{idx+1}] ")
        for k,v in slot.to_dict().items():
            print(f"{k}:{v}")